package view;

import control.PassengerController;
import model.Passenger;
import org.w3c.dom.Text;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public class pay implements ActionListener{
    public static JFrame jfra;
    public static JPanel jpan1, jpan2, jpanLabel, jpanCode, myPanel, jpanMid, jpanBlank, jpanButton;
    public static JLabel company, MyTripLabel, LogInLabel, ServiceLabel, VIPLabel, ModifyLabel, ContactLabel, label, payNotice, payNotice1;
    ;
    public static Font fnt3;
    public static JButton save, back;
    public static ImageIcon background;
    public static String currentPlaneNum;
    public static String bookNumber;
    public static PassengerController passengerController = new PassengerController();
    public static LogIn logIn = new LogIn();


    JTextField text4 = new JTextField(16);


    public void createPage() {
        jfra = new JFrame();


//setting the background
        background = new ImageIcon("src/view/image/background.png"); //Create a background image
        label = new JLabel(background);  //Add a background image to the label
        label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());//Set the label to be as wide as the image
        myPanel = (JPanel) jfra.getContentPane();  //Set myPanel to the Content panel
        myPanel.setOpaque(false);  //Make my panel invisible
        myPanel.setLayout(new FlowLayout());  //Set my panel to a flow layout
        jfra.getLayeredPane().setLayout(null);//Leave the layout of the layered panel blank

//create bar
        jpan1 = new JPanel();
        company = new JLabel("          Check-In Kiosk                    ", JLabel.LEFT);
        Font fnt = new Font("Serief", Font.BOLD, 40);
        company.setFont(fnt);
        LogInLabel = new JLabel("LogIn          ", JLabel.RIGHT);
        LogInLabel.setBackground(Color.YELLOW);
        MyTripLabel = new JLabel("MyTrip          ", JLabel.RIGHT);
        ServiceLabel = new JLabel("Service         ", JLabel.RIGHT);
        VIPLabel = new JLabel("VIP         ", JLabel.RIGHT);
        ModifyLabel = new JLabel("Board         ", JLabel.RIGHT);
        ContactLabel = new JLabel("Contact           ", JLabel.RIGHT);
        company.setForeground(Color.blue);
        jpan1.add(company);
        jpan1.add(LogInLabel);
        jpan1.add(MyTripLabel);
        jpan1.add(ServiceLabel);
        jpan1.add(VIPLabel);
        jpan1.add(ModifyLabel);
        jpan1.add(ContactLabel);
        jpan1.setVisible(true);


//create VIPpay box
        jpan2 = new JPanel(new BorderLayout());
        jpan2.setPreferredSize(new Dimension(320, 460));
        jpan2.setBackground(Color.WHITE);
        jpan2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),
                "code")));//Add the specific border of the panel
        jpanBlank = new JPanel();
        jpanBlank.setPreferredSize(new Dimension(300, 50));
        jpan2.add(jpanBlank, BorderLayout.NORTH);
        jpanBlank.setBackground(Color.WHITE);
//set middle panel
        jpanMid = new JPanel();
        jpanMid.setLayout(new FlowLayout());
        jpanMid.setPreferredSize(new Dimension(300, 300));
        jpanMid.setBackground(Color.WHITE);
        jpan2.add(jpanMid, BorderLayout.CENTER);

        jpanLabel = new JPanel(new FlowLayout());
        jpanLabel.setBackground(Color.WHITE);
        payNotice = new JLabel("Please Scan the Code",JLabel.CENTER);
        //payNotice.setPreferredSize(new Dimension(300,50));
        Font fnt3 = new Font("Serief", Font.ITALIC, 20);// Setting the size and style of the font.
        payNotice.setFont(fnt3);
        payNotice.setForeground(Color.BLACK);
        jpanLabel.add(payNotice);
        jpanMid.add(jpanLabel);
        jpanLabel.setVisible(true);

//Code picture
        jpanCode = new JPanel();
        jpanCode.setBackground(Color.WHITE);
        ImageIcon code=new ImageIcon("src/view/image/paycode.jpg");//Generate the icon picture for VIP seat
        code.setImage(code.getImage().getScaledInstance(200,200, 0));//Set the size of picture
        JLabel codepicture = new JLabel("", JLabel.CENTER);
        codepicture.setIcon(code);
        jpanCode.add(codepicture);
        jpanCode.setVisible(true);
        jpanMid.add(jpanCode);
        jpanMid.setVisible(true);
        jpan2.add(jpanMid);

        jpanButton = new JPanel(new FlowLayout());
        jpanButton.setPreferredSize(new Dimension(300, 100));
        save = new JButton("Finish");
        back = new JButton("Go Back");
        save.addActionListener(this);//Calling the listener
        back.addActionListener(this);//Calling the listener
        jpanButton.setBackground(Color.WHITE);
        save.setBackground(Color.WHITE);//Set the background color of the button
        back.setBackground(Color.WHITE);//Set the background color of the button
        jpanButton.add(back);
        jpanButton.add(save);
        jpan2.add(jpanButton, BorderLayout.SOUTH);

//Set myPanel
        myPanel.add(jpan1);
        myPanel.add(jpan2, BorderLayout.CENTER);
        jfra.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
//Set interface properties
        jfra.setBounds(300, 300, background.getIconWidth(), background.getIconHeight());
        jfra.setVisible(true);
        jfra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public void actionPerformed(ActionEvent e) {
        boolean check = (e.getSource() == save);
        boolean goback = (e.getSource() == back);
        if (check) {                                                  // if the user click the "login" button
            jfra.setVisible(false);
            view.Board tips = new view.Board();//Get the board information window
        }
        if(goback){
            jfra.setVisible(false);
            VIPpay page = new VIPpay();
        }
    }
}